// ==UserScript==
// @name WME-colour-blind
// @description   Tools for Waze Map Editor, it changes turn's arrow for colour-blind.
// @namespace     wme-champs-it
// @version       0.0.3
// @resource      turns.png http://colour-blind.googlecode.com/svn/trunk/turns.png
// @resource      colour-blind.css http://colour-blind.googlecode.com/svn/trunk/colour-blind.css
// @resource      colour-blind.js http://colour-blind.googlecode.com/svn/trunk/colour-blind.js
// @match         https://*.waze.com/beta_editor/*
// @include       https://*.waze.com/beta_editor/*
// ==/UserScript==

/*
 * Copyright (c) 2013+ Zannax
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
 */

var createElement;
var getURL;
var setCSS;
var isChrome = window.navigator.vendor.match(/Google/);
var isGM_TM = false;

function testGM_TM() {
  try {
    isGM_TM = (typeof GM_getResourceURL === "function");
  }
  catch (err) { /* Ignore */ }
}

createElement = function(type, attributes) {
	var node = document.createElement(type);
	for (var attr in attributes)
		if (attributes.hasOwnProperty(attr)) {
			node.setAttribute(attr, attributes[attr]);
		}
	return node;
};

getURL = function(path) {
	if (!isGM_TM && isChrome) {
		return chrome.extension.getURL(path);
	} else {
		return GM_getResourceURL(path);
	}
};

setCSS = function(path) {
	if (!isGM_TM && isChrome) {
		var css = createElement('link', {rel: 'stylesheet', type: 'text/css', href: getURL(path)});
		document.head.appendChild(css);
	} else {
		var cssTxt = GM_getResourceText(path);
		cssTxt = cssTxt.replace(/(url\(')(.*?)('\))/g,
						function($0, $1, $2, $3) {
							return($1 + GM_getResourceURL($2) + $3);
						});
		GM_addStyle(cssTxt);
	}
};

setJS = function(path) {
	var js = createElement('script', {src: getURL(path), async: false});
	document.head.appendChild(js);
};

testGM_TM();
setCSS("colour-blind.css");
//setJS("colour-blind.js");
